/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

export const validateNotNull = (r,v,c) => {
  if(!v){
    return c(new Error('请输入'))
  }else{
    c();
  }
}

export const validateUpload = (r,v,c) => {
  if(!v){
    return c(new Error('请上传文件'))
  }else{
    c();
  }
}

export const validateDatetime = (r,v,c) => {
  if(!v){
    return c(new Error('请选择时间'))
  }else{
    c();
  }
}

export const validateDatetimeRange = (r,v,c) => {
  if(!v || !v.length){
    return c(new Error('请选择时间'))
  }else{
    c();
  }
}

export const validateNotNullArray = (r,v,c) => {
  if(!v.length){
    return c(new Error('请上传文件'))
  }else{
    c();
  }
}
